Page({
  data:{
    visitorList:[],
    queryDate:{
      current:1,
      pageSize:10
    },
    isFinished:false,
    isLoading:false
  },
  onLoad(){
    this.getVisitorList()
  },
  // 获取访客列表
  async getVisitorList(){
   this.setData({
    isLoading:true
   })
   try {
    const {total,rows}=await wx.http.get('/visitor',this.data.queryDate) 
    if(total>this.data.visitorList.length){
      this.setData({
        'queryDate.current':this.data.queryDate.current+1
      })
    }else{
      this.setData({
        isFinished:true
      })
    }
    this.setData({
      visitorList:[...this.data.visitorList,...rows]
    })
   } catch (error) {
    console.log(error)
   }finally{
    this.setData({
      isLoading:false
     })
   }
  },
  // 容器内容滚动事件
  scrollToLower(){
    if(this.data.isFinished){
      return wx.utils.toast('没有更多内容了')
    }
    if(this.data.isLoading){
      return
    }
    this.getVisitorList()
  },
  goPassport({mark}) {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index?id='+ mark.id,
    })
  },
})
